package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.LoginBean;
import com.yiwei.hdb.api.bean.SignBean;
import com.yiwei.hdb.api.callback.LoginContract;
import com.yiwei.hdb.api.callback.SignContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class SignRequest extends BaseRequest<SignContract.View> implements SignContract.Presenter<SignContract.View> {

    public static SignRequest create() {
        return new SignRequest();
    }


    @Override
    public void getSign(String years, String months) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        SignBean bean = new SignBean();
        bean.months = months;
        bean.years = years;
        Api.api_service.getMySign(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getSignSuccess(result);
                });
    }

    @Override
    public void gotoSign() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.gotoSign().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.gotoSignSuccess(result);
                });
    }

    @Override
    public void getSignTask() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getSignTask().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getSignTask(result);
                });
    }
}
